﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace yao.Common
{
    public class SSOHelper
    {
        private static object _object=new object();
        private static Dictionary<string,string> DicOnline
        {
            get { return HttpContext.Current.Application["OnLine"] as Dictionary<string,string>; }
        }

        public static void LoginRegister(string key, string value)
        {
            if (DicOnline == null)
            {
                HttpContext.Current.Application.Lock();
                HttpContext.Current.Application["Online"] = new Dictionary<string, string>(); ;
                HttpContext.Current.Application.UnLock();
            }
            lock (_object)
            {
                if (!DicOnline.ContainsKey(key))
                {
                    DicOnline.Add(key, value);
                }
                else
                {
                    DicOnline[key] = value;
                }
            }
        }

        public static string GetLoginer(string key)
        {
            lock (_object)
            {
                if (DicOnline == null)
                {
                    return string.Empty;
                }
                if (DicOnline.ContainsKey(key))
                {
                    return DicOnline[key];
                }
                return string.Empty;
            }
        }        
    }
}
